
from alchemy import meta, settings

import new
import sys

CONFIGURED = False

def configure():
    global CONFIGURED
    if not CONFIGURED:
        for app_name, db_config in meta.config_list.items():
            module = new.module(app_name)
            code = "from %s.%s import *"
            if db_config.db_module:
                code = code % (meta.PROJECT_NAME, db_config.db_module)
            else:
                code = code % (meta.ALCHEMY_MODELS_ROOT, app_name)
            exec code in module.__dict__
            sys.modules['alchemy.models.%s' % app_name] = module
            globals()[app_name] = module
        CONFIGURED = True

configure()

